home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / text / edit / vim60rt.lha / Vim / vim60 / syntax / xml.vim < prev    next >
Encoding:
Text File  |  2001-09-13  |  6.3 KB  |  234 lines

  1. " Vim syntax file
  2. " Language:    XML
  3. " Maintainer:    Johannes Zellner <johannes@zellner.org>
  4. "        Author and previous maintainer:
  5. "        Paul Siegmann <pauls@euronet.nl>
  6. " Last Change:    Don, 13 Sep 2001 01:33:20 +0200
  7. " Filenames:    *.xml
  8. " URL:        http://www.zellner.org/vim/syntax/xml.vim
  9. " $Id: xml.vim,v 1.36 2001/09/12 23:37:25 joze Exp $
  10.  
  11. " CREDITS:
  12. "   The original version was derived by Paul Siegmann from
  13. "   Claudio Fleiner's html.vim.
  14. "
  15. " REFERENCES:
  16. "   [1] http://www.w3.org/TR/2000/REC-xml-20001006
  17. "   [2] http://www.w3.org/XML/1998/06/xmlspec-report-19980910.htm
  18. "
  19. "   as <hirauchi@kiwi.ne.jp> pointed out according to reference [1]
  20. "
  21. "   2.3 Common Syntactic Constructs
  22. "   [4]    NameChar    ::=    Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender
  23. "   [5]    Name        ::=    (Letter | '_' | ':') (NameChar)*
  24. "
  25. " NOTE:
  26. "   1) empty tag delimiters "/>" inside attribute values (strings)
  27. "      confuse syntax highlighting.
  28. "   2) for large files, folding can be pretty slow, especially when
  29. "      loading a file the first time and viewoptions contains 'folds'
  30. "      so that folds of previous sessions are applied.
  31. "      Don't use 'foldmethod=syntax' in this case.
  32.  
  33.  
  34. " Quit when a syntax file was already loaded
  35. if exists("b:current_syntax")
  36.     finish
  37. endif
  38.  
  39. let s:xml_cpo_save = &cpo
  40. set cpo&vim
  41.  
  42. syn case match
  43.  
  44. " mark illegal characters
  45. syn match xmlError "[<&]"
  46.  
  47. " strings (inside tags) aka VALUES
  48. "
  49. " EXAMPLE:
  50. "
  51. " <tag foo.attribute = "value">
  52. "                      ^^^^^^^
  53. syn region  xmlString contained start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=xmlEntity display
  54. syn region  xmlString contained start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=xmlEntity display
  55.  
  56.  
  57. " punctuation (within attributes) e.g. <tag xml:foo.attribute ...>
  58. "                                              ^   ^
  59. " syn match   xmlAttribPunct +[-:._]+ contained display
  60. syn match   xmlAttribPunct +[:.]+ contained display
  61.  
  62. " no highlighting for xmlEqual (xmlEqual has no highlighting group)
  63. syn match   xmlEqual +=+ display
  64.  
  65.  
  66. " attribute, everything before the '='
  67. "
  68. " PROVIDES: @xmlAttribHook
  69. "
  70. " EXAMPLE:
  71. "
  72. " <tag foo.attribute = "value">
  73. "      ^^^^^^^^^^^^^
  74. "
  75. syn match   xmlAttrib
  76.     \ +[-'"<]\@<!\<[a-zA-Z:_][-.0-9a-zA-Z0-9:_]*\>\(['">]\@!\|$\)+
  77.     \ contained
  78.     \ contains=xmlAttribPunct,@xmlAttribHook
  79.     \ display
  80.  
  81.  
  82. " start tag
  83. " use matchgroup=xmlTag to skip over the leading '<'
  84. "
  85. " PROVIDES: @xmlTagHook
  86. "
  87. " EXAMPLE:
  88. "
  89. " <tag id="whoops">
  90. " s^^^^^^^^^^^^^^^e
  91. "
  92. syn region   xmlTag
  93.     \ matchgroup=xmlTag start=+<[^ /!?<>"']\@=+
  94.     \ matchgroup=xmlTag end=+>+
  95.     \ contained
  96.     \ contains=xmlError,xmlAttrib,xmlEqual,xmlString,@xmlTagHook
  97.  
  98.  
  99. " highlight the end tag
  100. "
  101. " PROVIDES: @xmlTagHook
  102. " (should we provide a separate @xmlEndTagHook ?)
  103. "
  104. " EXAMPLE:
  105. "
  106. " </tag>
  107. " ^^^^^^
  108. "
  109. syn match   xmlEndTag
  110.     \ +</[^ /!?<>"']\+>+
  111.     \ contained
  112.     \ contains=@xmlTagHook
  113.  
  114.  
  115. " tag elements with syntax-folding.
  116. " NOTE: NO HIGHLIGHING -- highlighing is done by contained elements
  117. "
  118. " PROVIDES: @xmlRegionHook
  119. "
  120. " EXAMPLE:
  121. "
  122. " <tag id="whoops">
  123. "   <!-- comment -->
  124. "   <another.tag></another.tag>
  125. "   <empty.tag/>
  126. "   some data
  127. " </tag>
  128. syn region   xmlRegion
  129.     \ start=+<\z([^ /!?<>"']\+\)+
  130.     \ skip=+<!--\_.\{-}-->+
  131.     \ end=+</\z1\_\s\{-}>+
  132.     \ matchgroup=xmlEndTag end=+/>+
  133.     \ fold
  134.     \ contains=xmlTag,xmlEndTag,xmlCdata,xmlRegion,xmlComment,xmlEntity,xmlProcessing,@xmlRegionHook
  135.     \ keepend
  136.     \ extend
  137.  
  138.  
  139. " &entities; compare with dtd
  140. syn match   xmlEntity                 "&[^; \t]*;" contains=xmlEntityPunct
  141. syn match   xmlEntityPunct  contained "[&.;]"
  142.  
  143.  
  144. " The real comments (this implements the comments as defined by xml,
  145. " but not all xml pages actually conform to it. Errors are flagged.
  146. syn region  xmlComment                start=+<!+        end=+>+ contains=xmlCommentPart,xmlString,xmlCommentError,xmlTodo,@xmlCommentHook extend
  147. syn keyword xmlTodo         contained TODO FIXME XXX display
  148. syn match   xmlCommentError contained "[^><!]"
  149. syn region  xmlCommentPart  contained start=+--+        end=+--+
  150.  
  151.  
  152. " CData sections
  153. "
  154. " PROVIDES: @xmlCdataHook
  155. "
  156. syn region    xmlCdata
  157.     \ start=+<!\[CDATA\[+
  158.     \ end=+]]>+
  159.     \ contains=xmlCdataStart,xmlCdataEnd,@xmlCdataHook
  160.     \ keepend
  161.     \ extend
  162.  
  163. " using the following line instead leads to corrupt folding at CDATA regions
  164. " syn match    xmlCdata      +<!\[CDATA\[\_.\{-}]]>+  contains=xmlCdataStart,xmlCdataEnd,@xmlCdataHook
  165. syn match    xmlCdataStart +<!\[CDATA\[+  contained contains=xmlCdataCdata
  166. syn keyword  xmlCdataCdata CDATA          contained
  167. syn match    xmlCdataEnd   +]]>+          contained
  168.  
  169.  
  170. " Processing instructions
  171. " This allows "?>" inside strings -- good idea?
  172. syn region  xmlProcessing matchgroup=xmlProcessingDelim start="<?" end="?>" contains=xmlAttrib,xmlEqual,xmlString
  173.  
  174.  
  175. " DTD -- we use dtd.vim here
  176. syn region  xmlDocType matchgroup=xmlDocTypeDecl
  177.     \ start="<!DOCTYPE"he=s+2,rs=s+2 end=">"
  178.     \ fold
  179.     \ contains=xmlDocTypeKeyword,xmlInlineDTD,xmlString
  180. syn keyword xmlDocTypeKeyword contained DOCTYPE PUBLIC SYSTEM
  181. syn region  xmlInlineDTD contained matchgroup=xmlDocTypeDecl start="\[" end="]" contains=@xmlDTD
  182. syn include @xmlDTD <sfile>:p:h/dtd.vim
  183. unlet b:current_syntax
  184.  
  185.  
  186. " synchronizing
  187. " TODO !!! to be improved !!!
  188.  
  189. syn sync match xmlSyncDT grouphere  xmlDocType +\_.\(<!DOCTYPE\)\@=+
  190. " syn sync match xmlSyncDT groupthere  NONE       +]>+
  191.  
  192. syn sync match xmlSync grouphere   xmlRegion  +\_.\(<[^ /!?<>"']\+\)\@=+
  193. " syn sync match xmlSync grouphere  xmlRegion "<[^ /!?<>"']*>"
  194. syn sync match xmlSync groupthere  xmlRegion  +</[^ /!?<>"']\+>+
  195.  
  196. syn sync minlines=100
  197.  
  198.  
  199. " The default highlighting.
  200. hi def link xmlTodo        Todo
  201. hi def link xmlTag        Function
  202. hi def link xmlEndTag        Identifier
  203. hi def link xmlEntity        Statement
  204. hi def link xmlEntityPunct    Type
  205.  
  206. hi def link xmlAttribPunct    Comment
  207. hi def link xmlAttrib        Type
  208.  
  209. hi def link xmlString        String
  210. hi def link xmlComment        Comment
  211. hi def link xmlCommentPart    Comment
  212. hi def link xmlCommentError    Error
  213. hi def link xmlError        Error
  214.  
  215. hi def link xmlProcessingDelim    Comment
  216. hi def link xmlProcessing    Type
  217.  
  218. hi def link xmlCdata        String
  219. hi def link xmlCdataCdata    Statement
  220. hi def link xmlCdataStart    Type
  221. hi def link xmlCdataEnd        Type
  222.  
  223. hi def link xmlDocTypeDecl    Function
  224. hi def link xmlDocTypeKeyword    Statement
  225. hi def link xmlInlineDTD    Function
  226.  
  227. let b:current_syntax = "xml"
  228.  
  229. let &cpo = s:xml_cpo_save
  230. unlet s:xml_cpo_save
  231.  
  232. " vim: ts=8
  233.